home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Utils / NoScript / Bin / noscript-1.1.3.9-fx+fl+mz.xpi / install.js < prev    next >
Encoding:
Text File  |  2006-01-26  |  3.7 KB  |  100 lines

  1. const APP_DISPLAY_NAME = "NoScript";
  2. const APP_NAME = "noscript";
  3. const APP_PACKAGE = "/informaction/noscript";
  4. const APP_VERSION = "1.1.3.9";
  5.  
  6. const APP_PREFS_FILE="defaults/preferences/noscript.js";
  7. const APP_XPCOM_SERVICE="components/noscriptService.js";
  8. const APP_JAR_FILE = "noscript.jar";
  9. const APP_CONTENT_FOLDER = "content/noscript/";
  10. const APP_LOCALES = [
  11.   "es-ES","cs-CZ","pl-PL","ja-JP","ca-AD","pt-PT","pt-BR","de-DE","nb-NO",
  12.   "fi-FI","fr-FR","it-IT","nl-NL","tr-TR","zh-CN","ru-RU","bg-BG","ro-RO",
  13.   "sk-SK", "hu-HU", "zh-TW", "en-US"
  14.   ];
  15.  
  16. const APP_SUCCESS_MESSAGE = APP_DISPLAY_NAME+" should now be available when you restart Mozilla.";
  17.  
  18. const INST_TO_PROFILE = "Do you wish to install "+APP_DISPLAY_NAME+" to your profile?\nThis will mean it does not need reinstalling when you update Mozilla.\n(Click Cancel if you want "+APP_DISPLAY_NAME+" installing to the Mozilla directory.)";
  19.  
  20. var instToProfile = true;
  21.  
  22. myPerformInstall(false);
  23.  
  24. function myPerformInstall(secondTry) {
  25.   
  26.   var err;
  27.   initInstall(APP_NAME, APP_PACKAGE, APP_VERSION);
  28.   
  29.   if(!secondTry) {  
  30.     // profile installs only work since 2003-03-06
  31.     instToProfile = (buildID>2003030600 && confirm(INST_TO_PROFILE));
  32.   }
  33.   
  34.   var chromef = instToProfile ? getFolder("Profile", "chrome") : getFolder("chrome");
  35.   err = addFile(APP_PACKAGE, APP_VERSION, "chrome/" + APP_JAR_FILE, chromef, null);
  36.   
  37.   if(APP_PREFS_FILE && (err == SUCCESS) ) {
  38.     const prefDirs=[
  39.       getFolder(getFolder("Profile"),"pref"),
  40.       getFolder(getFolder(getFolder("Program"),"defaults"),"pref")
  41.       ];
  42.     for(var j=prefDirs.length; j-->0;) {
  43.       var prefDir=prefDirs[j];
  44.       if(!File.exists(prefDir)) {
  45.         File.dirCreate(prefDir);
  46.       }
  47.       err = addFile(APP_PACKAGE, APP_VERSION,  APP_PREFS_FILE, prefDir, null, true);
  48.       logComment("Adding "+APP_PREFS_FILE+" in "+prefDir+": exit code = "+err);
  49.     }
  50.   }
  51.   
  52.   if(err == SUCCESS) {
  53.     var jar = getFolder(chromef, APP_JAR_FILE);
  54.     const chromeFlag=instToProfile?PROFILE_CHROME:DELAYED_CHROME;
  55.   
  56.     registerChrome(CONTENT | chromeFlag, jar, APP_CONTENT_FOLDER);
  57.     var localesCount=APP_LOCALES.length;
  58.     if(localesCount>0) {
  59.       registerChrome(LOCALE | chromeFlag, jar, "content/noscript/"+APP_LOCALES[--localesCount]+"/");
  60.       while(localesCount-- >0) {
  61.         registerChrome(LOCALE  | chromeFlag, jar, "locale/"+APP_LOCALES[localesCount]+"/noscript/");
  62.       }
  63.     }
  64.     registerChrome(SKIN | chromeFlag, jar, "skin/classic/noscript/");
  65.     
  66.     
  67.     if(APP_XPCOM_SERVICE) {
  68.       var componentsDir = getFolder("Components");
  69.       addFile(APP_PACKAGE,APP_VERSION, APP_XPCOM_SERVICE, componentsDir, null, true);
  70.       addFile(APP_NAME, "components/.autoreg", getFolder("Program"), "");
  71.     }
  72.     
  73.     err = performInstall();
  74.     if(err == -239 && !secondTry) {
  75.       alert("Chrome registration problem, maybe transient, retrying...");
  76.       cancelInstall(err);
  77.       myPerformInstall(true);
  78.       return;
  79.     }
  80.     if(err == SUCCESS || err == 999) {
  81.       alert(APP_DISPLAY_NAME+" "+APP_VERSION+" has been succesfully installed.\n"+APP_SUCCESS_MESSAGE);
  82.     } else {
  83.       var msg = "Install failed!!! Error code:" + err;
  84.  
  85.       if(err == -239) {
  86.         msg += "\nThis specific error is usually transient:"
  87.           +"\nif you retry to install again, it will probably go away."
  88.       }
  89.  
  90.       alert(msg);
  91.       cancelInstall(err);
  92.     }
  93.   } else {
  94.     alert("Failed to create " +APP_JAR_FILE +"\n"
  95.       +"You probably don't have appropriate permissions \n"
  96.       +"(write access to your profile or chrome directory). \n"
  97.       +"_____________________________\nError code:" + err);
  98.     cancelInstall(err);
  99.   }
  100. }